package com.fast.develop.management;

import com.fast.develop.core.io.ResourceManager;
import com.fast.develop.management.resource.compoment.RepositoryResourceTreeManager;
import com.fast.develop.meta.base.MetaConfiguration;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;


/**
 * @author 莫寅
 * @createTime 2022-06-23 13:50
 * @desc：
 */
@Slf4j
public class ManagementConfiguration{

    private ResourceManager resourceManager;

    private ResourceTreeManager resourceTreeManager;

    private MetaConfiguration metaConfiguration;

    public ManagementConfiguration(ResourceManager resourceManager, MetaConfiguration metaConfiguration)  {
        this.resourceManager = resourceManager;
        this.metaConfiguration = metaConfiguration;
        refresh();
    }

    @SneakyThrows
    private void refresh() {
        print();
        initMetaConfiguration();
    }

    private void initMetaConfiguration(){
//        this.metaConfiguration = new MetaConfiguration()
//                .register(new MetaResourceRegistor(), new MetaDomainRegistor())
//                .build();

        this.resourceTreeManager = new RepositoryResourceTreeManager(metaConfiguration, resourceManager);
    }

    private void print(){
        ClassLoader loader = Thread.currentThread().getContextClassLoader();
        log.info("ClassLoader mode = " + loader.getResource("").getPath());

        log.info("class.getResource'' mode = " + ManagementConfiguration.class.getResource("").getPath());

        log.info("class.getResource'/' mode = " + ManagementConfiguration.class.getResource("/").getPath());

        log.info("System.getProperty(\"user.dir\") mode = " + System.getProperty("user.dir"));
    }


    public ResourceManager getResourceManager() {
        return resourceManager;
    }

    public ResourceTreeManager getResourceTreeManager() {
        return resourceTreeManager;
    }

    public MetaConfiguration getMetaConfiguration() {
        return metaConfiguration;
    }


    public void reload(){
        resourceManager.reload();
        metaConfiguration.reload();
    }
}
